package com.smartleanx.module.hrm.controller.admin.examine.examineTemplate;

import static com.smartleanx.framework.common.pojo.CommonResult.success;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson2.JSONObject;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineTemplate.ExamineTemplateDO;
import com.smartleanx.module.hrm.service.examine.examineTemplate.ExamineTemplateService;

import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "管理后台 - 考核模板（方案/结果）")
@RestController
@RequestMapping("/hrm/examine-template")
@Validated
public class ExamineTemplateController {

    @Resource
    private ExamineTemplateService examineTemplateService;

    @GetMapping("/plan/page")
    public CommonResult<Object> getExaminePlanTemplateList(@RequestParam("pageNo") Integer pageNum,
        @RequestParam("pageSize") Integer pageSize, @RequestParam("templateName") String templateName) {
        PageResult<ExamineTemplateDO> result =
            examineTemplateService.getExaminePlanTemplateList(pageNum, pageSize, templateName);
        return CommonResult.success(result);
    }

    @PostMapping("/plan/create")
    public CommonResult<Object> createPlanTemplate(@Valid @RequestBody JSONObject param) {
        return success(examineTemplateService.createPlanTemplate(param));
    }

    @GetMapping("/plan/get")
    public CommonResult<Object> getPlanTemplateUpdateInfo(Integer id) {
        JSONObject result = examineTemplateService.getPlanTemplateUpdateInfo(id);
        return success(result);
    }

    @PostMapping("/plan/update")
    public CommonResult<Object> updatePlanTemplate(@Valid @RequestBody JSONObject param) {
        return success(examineTemplateService.updatePlanTemplate(param));
    }

    @GetMapping("/plan/delete")
    public CommonResult<Object> deletePlanTemplate(Integer id) {
        return success(examineTemplateService.deletePlanTemplate(id));
    }

    @GetMapping("/result/page")
    public CommonResult<Object> getExamineResultTemplateList(@RequestParam("pageNo") Integer pageNum,
        @RequestParam("pageSize") Integer pageSize, @RequestParam("templateName") String templateName) {
        PageResult<ExamineTemplateDO> result =
            examineTemplateService.getExamineResultTemplateList(pageNum, pageSize, templateName);
        return CommonResult.success(result);
    }

    @PostMapping("/result/create")
    public CommonResult<Object> createResultTemplate(@Valid @RequestBody JSONObject param) {
        return success(examineTemplateService.createResultTemplate(param));
    }

    @GetMapping("/result/get")
    public CommonResult<Object> getResultTemplateUpdateInfo(Integer id) {
        JSONObject result = examineTemplateService.getResultTemplateUpdateInfo(id);
        return success(result);
    }

    @PostMapping("/result/update")
    public CommonResult<Object> updateResultTemplate(@Valid @RequestBody JSONObject param) {
        return success(examineTemplateService.updateResultTemplate(param));
    }

    @GetMapping("/result/delete")
    public CommonResult<Object> deleteResultTemplate(Integer id) {
        return success(examineTemplateService.deleteResultTemplate(id));
    }

    @GetMapping("/result/select")
    public CommonResult<Object> getResultTemplateSelectList() {
        return success(examineTemplateService.getResultTemplateSelectList());
    }
}
